﻿//MIT License
//Copyright (c) 2024 nuaazgg, Nanjing University of Aeronautics and Astronautics(NUAA)

using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;

public class VirtualHand : MonoBehaviour
{
    public GameObject[] fingers;//从小拇指外端到内端，从小拇指到大拇指
    public ConcurrentQueue<float[]> handAngles = new ConcurrentQueue<float[]>();
    private Vector3[] initAngle;
    // Start is called before the first frame update
    void Start()
    {
        initAngle = new Vector3[10];
        for(int i=0;i<10;++i)
        {
            initAngle[i] = fingers[i].transform.localEulerAngles;
        }
        //fingers[0].transform.position
    }

    // Update is called once per frame
    void Update()
    {
        if (handAngles.TryDequeue(out var angles))
        {
            for (int i = 0; i < 8; ++i)
            {
                fingers[i].transform.localEulerAngles = new Vector3(angles[i], initAngle[i].y, initAngle[i].z);
                //transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(angle[0], y, angle[1]), Time.deltaTime * speed);
            }
            fingers[8].transform.localEulerAngles = new Vector3(initAngle[8].x, initAngle[8].y, initAngle[8].z + angles[8]);
            fingers[9].transform.localEulerAngles = new Vector3(angles[9], angles[10], initAngle[9].z);//TODO

        }

        
    }
}
